<template>
	<view>
		<view class="address-item" v-for="(item,index) in dataList" @click="selectAddress(item)">
			<view class="area-text">{{item.province}}{{item.city}}{{item.district}}</view>
			<view class="adress-text">{{item.address}}</view>
			<view class="flex-center user-back">
				<view class="user-name">{{item.name}}</view>
				<view class="user-mobile">{{item.mobile}}</view>
			</view>
			<view class="flex-end">
				<view class="button" @click.stop="deltAction(item)">删除</view>
				<view class="button edit" @click.stop="editAction(item)">编辑</view>
			</view>
		</view>
		<view class="bottomBt">
			<view @click="newAddress">新增收货地址</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "wts-addressList",
		props: {
			dataList: [],
		},
		data() {
			return {

			}
		},
		watch: {

		},
		methods: {
			// 删除地址
			deltAction(item) {
				uni.showModal({
					title: '提示',
					content: '确认删除该地址？',
					success: (onClick) => {
						if (onClick.confirm) {
							this.$emit('deletAddress', item)
						}
					}
				})
			},
			// 编辑地址
			editAction(item) {
				this.$emit('editAddress', item)
			},
			// 新增地址
			newAddress() {
				this.$emit('addAddress')
			},
			// 选择地址
			selectAddress(item) {
				this.$emit('selectAddress', item)
			}
		}
	}
</script>

<style lang="scss">
	.flex-center {
		display: flex;
		align-items: center;
	}

	.flex-end {
		display: flex;
		justify-content: flex-end;
	}

	.address-item {
		background-color: #fff;
		padding: 30rpx;
		border-bottom: #eee 2rpx solid;

		&:last-of-type {
			border-bottom: none;
		}

		.area-text {
			color: #666;
			font-size: 25rpx;
		}

		.adress-text {
			font-size: 28rpx;
			font-weight: bold;
			margin-top: 10rpx;
		}

		.user-back {
			font-size: 28rpx;
			margin-top: 10rpx;
			color: #444;

			.user-name {
				width: 200rpx;
			}
		}

		.button {
			background-color: #ccc;
			color: #666;
			font-size: 26rpx;
			line-height: 26rpx;
			padding: 18rpx 35rpx;
			border-radius: 8rpx;
			margin-top: 20rpx;
		}

		.edit {
			background-color: #a20000;
			color: #fff;
			margin-left: 20rpx;
		}
	}

	.bottomBt {
		width: 100%;
		padding: 20rpx;
		box-sizing: border-box;
		background: #fff;
		position: fixed;
		left: 0;
		bottom: 0;
		border-top: 1px solid #eee;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: calc(env(safe-area-inset-bottom) + 20rpx);
		z-index: 999;
		display: flex;
		align-items: center;
		justify-content: space-between;

		view {
			background-color: #a20000;
			color: #fff;
			height: 88rpx;
			width: 100%;
			border-radius: 38rpx;
			line-height: 88rpx;
			text-align: center;
		}
	}
</style>